# Start development environment script for Windows PowerShell

Write-Host "Starting development environment..." -ForegroundColor Green

# Check if Docker is running
$dockerStatus = docker info 2>&1
if ($LASTEXITCODE -ne 0) {
    Write-Host "Error: Docker is not running. Please start Docker Desktop and try again." -ForegroundColor Red
    exit 1
}

# Start Docker Compose services
Write-Host "Starting PostgreSQL and Redis services..." -ForegroundColor Cyan
docker compose -f docker-compose.dev.yaml up -d

# Wait for services to be ready
Write-Host "Waiting for services to be ready..." -ForegroundColor Cyan
Start-Sleep -Seconds 5

# Check if PostgreSQL is ready
$pgStatus = docker exec api-webservice-postgres pg_isready -U postgres 2>&1
if ($LASTEXITCODE -ne 0) {
    Write-Host "Warning: PostgreSQL might not be ready yet. You may need to wait a bit longer." -ForegroundColor Yellow
} else {
    Write-Host "PostgreSQL is ready!" -ForegroundColor Green
}

# Check if Redis is ready
$redisStatus = docker exec api-webservice-redis redis-cli ping 2>&1
if ($redisStatus -ne "PONG") {
    Write-Host "Warning: Redis might not be ready yet. You may need to wait a bit longer." -ForegroundColor Yellow
} else {
    Write-Host "Redis is ready!" -ForegroundColor Green
}

Write-Host ""
Write-Host "Development environment is set up!" -ForegroundColor Green
Write-Host ""
Write-Host "You can access the following services:" -ForegroundColor Cyan
Write-Host "- PostgreSQL: localhost:5432 (Username: postgres, Password: postgres)" -ForegroundColor White
Write-Host "- Redis: localhost:6379" -ForegroundColor White
Write-Host "- Redis Commander: http://localhost:8081" -ForegroundColor White
Write-Host ""
Write-Host "To start the NestJS application, run:" -ForegroundColor Cyan
Write-Host "npm run start:dev" -ForegroundColor White
Write-Host ""
Write-Host "To stop the development environment, run:" -ForegroundColor Cyan
Write-Host "docker compose -f docker-compose.dev.yaml down" -ForegroundColor White 